function getWarnValue()
{
    var warnval = {};

    $.ajax({
        type: "GET",
        url: "/Home/Admin/getSingleUser16pfWarnValue",
        dataType: "json",
        async: false,

        success: function (data) {
            warnval = data;

        }, error: function (jqXHR) {
            alert("failed" + jqXHR.status);
        }
    });


    var i = 0;

    var section = warnval.element_labels;

    console.log(section);

    $("#warn-set-list").find('tr').each(function(){

        var chosen = section[i];

        $input = $(this).find('td').eq(2).find('input');
        $input.val(warnval[i][chosen]);
        $select = $(this).find('td').eq(1).find('select');
        $select.get(0).selectedIndex= warnval[i].select;
        i++;
    });

    //json = JSON.stringify(json);

    //var jsonarr = [];
    //jsonarr.push(json);

    //console.log(jsonarr);

    $("#commit-warnvalue").click(function(){

        var json = {};
        var i = 0;
        $("#warn-set-list").find('tr').each(function(){
            $input = $(this).find('td').eq(2).find('input');
            $opt = $(this).find('td').eq(1).find('select');

            console.log($input.attr("id"));
            console.log($opt.get(0).selectedIndex);

            var obj = {};
            obj[$input.attr("id")] = $input.val();
            obj['select'] = $opt.get(0).selectedIndex;
            json[i] = obj;

            i ++;
        });

        json = JSON.stringify(json);

        var jsonarr = [];
        jsonarr.push(json);
        console.log(jsonarr);


        $.ajax({
            type: "POST",
            url: "/Home/Admin/setSingleUser16pfWarnValue",
            dataType: "json",
            async: false,
            data:{
                jsondata: jsonarr
            },
            success: function (data) {
                alert(data.msg);
                getWarnValue();

            }, error: function (jqXHR) {
                alert("failed" + jqXHR.status);
            }
        });
    });
}

function getWarnKey()
{
    $.ajax({
        type: "POST",
        url: "/Home/Admin/getSingleUser16pfWarnKey",
        dataType: "json",
        async: false,
        success: function (data) {
            var htmls = [];
            for (var i = 0; i < Object.keys(data).length; i++){
                htmls.push("<tr><td>"+data[i].element_name+"</td>");
                htmls.push("<td><select> <option>小于</option> <option>大于</option> </select></td>");
                htmls.push('<td><input type="number" id="'+data[i].element_label+'"></td></tr>');
            }

            $("#warn-set-list").html(htmls.join(''));

        }, error: function (jqXHR) {
            alert("failed" + jqXHR.status);
        }
    });
}


$(document).ready(function(){

    getWarnKey();
    getWarnValue();



});